﻿//using Microsoft.Extensions.Hosting;

//using System.Net;

//using ThingsGateway.Hardware.Info;
//using ThingsGateway.Hardware.Info.Components;

//namespace ThingsGateway.Core;
//public class ComputerService :   BackgroundService, ISingleton
//{
//    public ComputerService(RootServices rootServices)
//    {
//        rootServices.ComputerService= this;
//    }
//    public override async Task StartAsync(CancellationToken cancellationToken)
//    {
//        await base.StartAsync(cancellationToken);
//    }

//    public override Task StopAsync(CancellationToken cancellationToken)
//    {
//        return base.StopAsync(cancellationToken);
//    }
//    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
//    {
//        while (!stoppingToken.IsCancellationRequested)
//        {
//            //这里不采用CancellationToken控制子线程，直接循环保持
//            ComputerInfo = GetComputerInfo();
//            await Task.Delay(1000, stoppingToken);
//        }
//    }
//    public ComputerInfo ComputerInfo { get; set; }

//    /// <summary>
//    /// 全部信息
//    /// </summary>
//    /// <returns></returns>
//    public ComputerInfo GetComputerInfo()
//    {
//        HardwareInfo hardwareInfo = new HardwareInfo();
//        hardwareInfo.RefreshAll();
//        ComputerInfo computerInfo = hardwareInfo.Adapt<ComputerInfo>();
//        var programStartTime = Process.GetCurrentProcess().StartTime;
//        var programRunTime = DateTime.Now - programStartTime;
//        computerInfo.StartTime = programStartTime;
//        computerInfo.RunTime = (long)programRunTime.TotalSeconds;

//        computerInfo.HostName = Environment.MachineName; // 主机名称
//        computerInfo.SystemOs = RuntimeInformation.OSDescription;// 操作系统
//        computerInfo.OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(); // 系统架构
//        computerInfo.RemoteIp = ComputerUtil.GetIpFromPCOnline(); // 外网地址
//        computerInfo.FrameworkDescription = RuntimeInformation.FrameworkDescription; // NET框架
//        //var config = App.GetConfig<HttpServerSettings>("HttpServer", false);
//        //var warm = string.Format(@"https://{0}:{1}", config.IpAddress, config.HttpsPort);
//        //computerInfo.LocalIp = warm;
//        return computerInfo;
//    }


//}

//public class ComputerInfo
//{

//    public List<Battery> BatteryList { get; set; } = new List<Battery>();

//    public List<BIOS> BiosList { get; set; } = new List<BIOS>();

//    public List<CPU> CpuList { get; set; } = new List<CPU>();

//    public List<Drive> DriveList { get; set; } = new List<Drive>();

//    /// <summary>
//    /// DotNET版本
//    /// </summary>
//    [DisplayName(".NET版本")]
//    public string? FrameworkDescription { get; set; }

//    /// <summary>
//    /// 服务器名称
//    /// </summary>
//    [DisplayName("HostName")]
//    public string? HostName { get; set; }
//    public List<Keyboard> KeyboardList { get; set; } = new List<Keyboard>();

//    /// <summary>
//    /// 内网地址
//    /// </summary>
//    [DisplayName("内网地址")]
//    public string? LocalIp { get; set; }

//    public List<Memory> MemoryList { get; set; } = new List<Memory>();

//    public MemoryStatus MemoryStatus { get; set; } = new MemoryStatus();

//    public List<Hardware.Info.Components.Monitor> MonitorList { get; set; } = new List<Hardware.Info.Components.Monitor>();

//    public List<Motherboard> MotherboardList { get; set; } = new List<Motherboard>();

//    public List<Mouse> MouseList { get; set; } = new List<Mouse>();

//    public List<NetworkAdapter> NetworkAdapterList { get; set; } = new List<NetworkAdapter>();

//    public Hardware.Info.Components.OS OperatingSystem { get; set; } = new Hardware.Info.Components.OS();

//    /// <summary>
//    /// 系统架构
//    /// </summary>
//    [DisplayName("系统架构")]
//    public string? OsArchitecture { get; set; }

//    public List<Printer> PrinterList { get; set; } = new List<Printer>();

//    /// <summary>
//    /// 外网地址
//    /// </summary>
//    [DisplayName("外网地址")]
//    public string? RemoteIp { get; set; }

//    /// <summary>
//    /// 启动时间
//    /// </summary>
//    [DisplayName("启动时间")]
//    public long RunTime { get; set; }

//    public List<SoundDevice> SoundDeviceList { get; set; } = new List<SoundDevice>();

//    /// <summary>
//    /// 启动时间
//    /// </summary>
//    [DisplayName("启动时间")]
//    public DateTime StartTime { get; set; }

//    /// <summary>
//    /// 系统名称
//    /// </summary>
//    [DisplayName("系统名称")]
//    public string? SystemOs { get; set; }
//    public List<VideoController> VideoControllerList { get; set; } = new List<VideoController>();

//}
//public class IPAddressMapper : IRegister
//{

//    public void Register(TypeAdapterConfig config)
//    {
//        config.ForType<IPAddress, IPAddress>()
//        .MapWith(a => IPAddress.Parse(a.ToString()))
//            ;
//    }

//}
